using Godot;
using System;

public partial class Main : Node2D
{
    private TileMap TileMapNode;
    private Camera2D Camera2DNode;
    public override void _Ready()
    {
        TileMapNode = GetNode<TileMap>("TileMap");
        Camera2DNode = GetNode<Camera2D>("Player/Camera2D");
        var used = TileMapNode.GetUsedRect().Grow(-1);
        var tileSize = TileMapNode.TileSet.TileSize;

        Camera2DNode.LimitTop = used.Position.Y * tileSize.Y;
        Camera2DNode.LimitRight = used.End.X * tileSize.X;
        Camera2DNode.LimitBottom = used.End.Y * tileSize.Y;
        Camera2DNode.LimitLeft = used.Position.X * tileSize.X;
        Camera2DNode.ResetSmoothing();
    }
}
